/**
 * @File AssetClassDaoImpl.java
 * @author Dhruv
 * @Version 1.0
 * @Date April 18, 2013
 * 
 * Copyright (c) 2011 EdRP, Dayalbagh Educational Institute.
 * All Rights Reserved.
 *
 * Redistribution and use in source and binary forms, with or
 * without modification, are permitted provided that the following
 * conditions are met:
 *
 * Redistributions of source code must retain the above copyright
 * notice, this  list of conditions and the following disclaimer.
 *
 * Redistribution in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in
 * the documentation and/or other materials provided with the
 * distribution.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED.  IN NO EVENT SHALL ETRG OR ITS CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL,SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * Contributors: Members of EdRP, Dayalbagh Educational Institute
 */
package in.ac.dei.edrp.generalLedger.assetClass;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.orm.ibatis.SqlMapClientTemplate;
import org.springframework.stereotype.Component;

import com.ibatis.sqlmap.client.SqlMapClient;

@Component
@Qualifier("AssetClassDaoImpl")
public class AssetClassDaoImpl extends SqlMapClientTemplate implements AssetClassDao
{
private static Logger logObj = Logger.getLogger(AssetClassDaoImpl.class);
	
	AssetClassDaoImpl(){}
	
	@Autowired
	public AssetClassDaoImpl(SqlMapClient sqlMapClient)
	   {
		    setSqlMapClient(sqlMapClient);
	   }

	

	
	public List<AssetClassBean> getAllAssetClass(AssetClassBean input,String flag) 
	 {
		   List<AssetClassBean> list = null;
		      try{
			       if(flag.equalsIgnoreCase("assetClasses"))
			          {
				         list = getSqlMapClient().queryForList("assetClassSqlMap.getAllAssetClasses", input);
			          } 
			      else
			          {
				         list = getSqlMapClient().queryForList("assetClassSqlMap.getAllAssetSubClasses", input);
			          } 
		        }
		         catch(Exception e)
		              {
			              logObj.error("Error inside getAllAssetClass method of AssetClassDaoImpl Class: ", e);
	               	  } 
		return list;
	} 

	public String setAssetClasses(AssetClassBean input) 
	{
	     	String status = "";
		
		        try{
			         getSqlMapClient().insert("assetClassSqlMap.setAssetClasses", input);
			         status = "insert";
			
		           }catch(Exception ex)
		                {
			              status="Exception";
			              logObj.info("Exception in setAsset Class method");
			              logObj.error(ex);
			             
			              }
	  	return status;
	}
	
	
	@SuppressWarnings("unchecked")
	public List<AssetClassBean> getAssetClassCodeClassName(AssetClassBean input)
	{
		     List<AssetClassBean> list = null;
		          try{
		                list = getSqlMapClient().queryForList("assetClassSqlMap.getAssetClassCodeClassName", input);
		                
	                 }catch(Exception e)
	                 {
				       logObj.error("Error inside getAssetClassCodeClassName method of AssetClassDaoImpl Class: ", e);
	                 }
	      return list;
	      
	}
	
	public String setAssetSubClasses(AssetClassBean input) 
	{
	        	String status = "";
               try{
           			 if (input.getFlag().equalsIgnoreCase("N"))
			              {
			                getSqlMapClient().insert("assetClassSqlMap.setAssetSubClasses", input);
			                status= "insert";
	                      }
			         else
			              {
				            getSqlMapClient().update("assetClassSqlMap.updateAssetSubClasses", input);
			                status= "update";
			              }
			 
		                  } 
               catch(Exception ex)
                          {
			             	status="Exception";
				            logObj.info("Exception in setAsset SubClass method"+ ex);
				            logObj.error(ex);
		                  } 
		return status; 
	}

	public String deleteAssetClasses(AssetClassBean input)
	{
	            String status = "" ;
	     
	            try
	            {	    	
	    	       getSqlMapClient().delete("assetClassSqlMap.deleteAssetClasses", input);
	    	       status = "delete"; 
	            }catch(Exception ex){
				status="Exception";
				logObj.info("Exception in setAsset SubClass method"+ ex);
		        logObj.error(ex);
	        }
	        return status ;
	}
	
	public String deleteAssetSubClasses(AssetClassBean input)
    {
	          String status = "" ;
	     
	             try
	             {
	               getSqlMapClient().delete("assetClassSqlMap.deleteAssetSubClasses", input);
	    	       status = "delete"; 
	             }catch(Exception ex)
	             {
				   status="Exception";
				   logObj.info("Exception in setAsset SubClass method"+ ex);
		           logObj.error(ex);
	             }
	        return status ;
	
	}

}
